-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
add conditional to check ndim
#63058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Please review this. |
|
Does this PR address an open issue? |
Not any issue which I know of. But, I thought that it should raise an error. So, I made the PR. |
|
Sorry for being pedantic about this, but since this is a change in behavior, I think it's best to:
|
I will do what you said. But, I am still learning. I do not know to create tests. Please help me with that. |
|
Issue created for this PR #63112 |
|
I think that |
I will do that. Should I make a new PR for that? |
It should be done in this one. |
Thank you for helping. I will create the tests. |
|
pre-commit failed because the max characters allowed in a line exceeded. I did not know about the max allowed characters. Sorry for that. |
pandas/tests/arrays/test_array.py
Outdated
|
|
||
| @pytest.mark.parametrize("data", [np.array(0)]) | ||
| def test_nd_raises(data): | ||
| @pytest.mark.parametrize("data,dtype", [(np.array(0),"int64"),(np.array([[1, 2], ["a", "b"]]),object)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can fix the formatting with pre-commit. The docs have a section about it. It's also good to create a development environment.
To fix the formatting, setup pre-commit and run
pre-commit run --files pandas/tests/arrays/test_array.py
pandas/core/construction.py
Outdated
| if data.ndim != 1: | ||
| raise ValueError("NumpyExtensionArray must be 1-dimensional") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test shows that the verification shouldn't be put here. I think the correct place is pandas/core/arrays/numpy_.py
Change dimensionality check for NumpyExtensionArray.
|
Tried making changes to |
Description
It checks the value of
ndimwhen the argument fordatais annp.ndarrayinpandas.array(data, dtype=None, copy=True)Reason
Raises an error because the array is 2-D
Does not raise an error in this case(maybe, because the value is now a string). But, it should raise an error as only 1-D arrays can be passed as arguments.
resolves #63112